<?php

// 日志
class rizhiModule extends Model
{
    public function __construct()
    {
        parent::__construct("rizhi");
    }

    /**
     * 查询点赞情况
     * @date: 2019年2月14日 下午5:31:38
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function iszan($laiyuanbianhao, $yonghuid, $leixing, $laiyuan)
    {
        $detail = $this
            ->where("yonghu='{$yonghuid}' and laiyuanbianhao='$laiyuanbianhao' and leixing='{$leixing}' and laiyuan='{$laiyuan}' ")
            ->all();
        if (count($detail) > 0) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 消赞
     * @date: 2019年2月14日 下午7:16:11
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function delzan($laiyuanbianhao, $yonghuid, $leixing, $laiyuan)
    {
        $detail = $this
            ->where("yonghu='{$yonghuid}' and laiyuanbianhao='$laiyuanbianhao' and leixing='{$leixing}'  and laiyuan='{$laiyuan}'  ")
            ->one();
        if (count($detail) > 0) {
            $this->delete($detail['id']);
            return true;
        } else {
            return false;
        }
    }

    /**
     * 点赞
     * @date: 2019年2月15日 下午2:17:33
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function addzan($laiyuanbianhao, $yonghuid, $leixing, $laiyuan = "")
    {
        $detail = $this
            ->where("yonghu='{$yonghuid}' and laiyuanbianhao='$laiyuanbianhao' and leixing='{$leixing}' and laiyuan='{$laiyuan}' ")
            ->all();
        if (count($detail) == 0) {
            $commonClass = new Common();
            //处理查询表
            $tableName = "rizhi";
            //待处理的表
            $tableModel = new Model($tableName);
            $moxingModel = new tableModel();
            $model_id = $moxingModel->gettableidBytablename($tableName);
            //1.收集表单数据
            $data = $tableModel->getFieldArray();
            //2.验证和处理
            $this->helper('input');
            $data = deepspecialchars($data);

            //时间默认为空则为当前时间
            if (!isset($data['dtime'])) {
                $data['dtime'] = date("Y-m-d H:i:s");
            }
            if ($tableModel->insert($data)) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }

}